package com.hcc.security.service.serviceImpl;

import com.hcc.security.mapper.persistentLoginsMapper;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
import org.springframework.stereotype.Service;

/**
 * 自定义token
 *
 * @version 1.0
 * @author: Administrator
 * @date: 2019/4/28
 */
@Slf4j
@Service
public class MyPersistentTokenRepository implements PersistentTokenRepository {

  @Autowired
  private persistentLoginsMapper persistentLoginsMapper;

  @Override
  public void createNewToken(PersistentRememberMeToken persistentRememberMeToken) {
    log.info("createNewToken: "+persistentRememberMeToken.getTokenValue());
    //TODO save

  }

  @Override
  public synchronized void updateToken(String series, String tokenValue, Date date) {
    PersistentRememberMeToken token = this.getTokenForSeries(series);
    PersistentRememberMeToken newToken = new PersistentRememberMeToken(token.getUsername(), series, tokenValue, new Date());
    //TODO update
  }


  @Override
  public PersistentRememberMeToken getTokenForSeries(String seriesId) {
    //TODO get
    //return (PersistentRememberMeToken)this.seriesTokens.get(seriesId);
    return null;
  }

  @Override
  public void removeUserTokens(String userName) {
    //TODO remove
  }
}
